﻿package
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import com.thaiflashdev.utils.KeyObject;
	import com.thaiflashdev.utils.KeyCode;
	
	public class KeyObjectTest extends MovieClip
	{
		private var ko:KeyObject;
		private var txt:String = "You press ";
		
		public function KeyObjectTest()
		{
			setupConstructors();
			setupListeners();
		}
		
		private function setupConstructors():void
		{
			ko = KeyObject.getListenerInstance(stage);
		}
		
		private function setupListeners():void
		{
			stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
		}
		
		private function enterFrameHandler(e:Event):void
		{
			var key:int = ko.pressingKey;
			var word:String = "";
			switch(key) {
				case KeyCode.A :{
					word = "A";
					break;
				}
				case KeyCode.B :{
					word = "B";
					break;
				}
				case KeyCode.C :{
					word = "C";
					break;
				}
				case KeyCode.D :{
					word = "D";
					break;
				}
				case KeyCode.LEFT :{
					word = "LEFT";
					break;
				}
				case KeyCode.RIGHT :{
					word = "RIGHT";
					break;
				}
				case KeyCode.UP :{
					word = "UP";
					break;
				}
				case KeyCode.DOWN :{
					word = "DOWN";
					break;
				}
				case 0 :{
					word = "NOTHING";
					break;
				}
				default :{
					word = "THE OTHER";
				}
			}
			ShowText.text = (txt + word).toString();
		}
	}
}